{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3f52c8a67c96bf50",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "# 思路\n",
    "一、数据清洗\n",
    "1. 完整性验证\n",
    "2. 是否存在缺失值\n",
    "3. 特征数值如何处理\n",
    "4. 哪些想要，哪些需要过滤\n",
    "5. 将有价值的信息做成新的数据源\n",
    "6. 去除无行为交互的商品和用户\n",
    "7. 去除流量大而购买量少的用户（爬虫用户）\n",
    "二、数据理解和分析\n",
    "1. 掌握特征含义\n",
    "2. 观察数据有哪些特点，是否可以利用来建模\n",
    "3. 可视化展示便于分析\n",
    "4. 用户的购买意向是否随时间变化\n",
    "三、特征提取\n",
    "1. 基于清洗后的数据集哪些特征是有价值的\n",
    "2. 分别对用户与商品以及其之间构成的行为进行特征提取\n",
    "3. 行为因素中哪些是核心？如何提取\n",
    "4. 瞬时行为特征 累计行为特征\n",
    "四、模型建立\n",
    "1. 使用机器学习算法进行预测\n",
    "2. 参数设置与调节\n",
    "3. 数据集切分"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb14be7204e52b81",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "# 一、数据预处理"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75bdf36064620d6c",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "## 导入数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "618b1222e9e6e8f7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:15.734243700Z",
     "start_time": "2024-03-14T13:13:15.720294Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import warnings\n",
    "import numpy as np\n",
    "from datetime import datetime\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "from collections import Counter\n",
    "\n",
    "#设置为seaborn风格\n",
    "sns.set()\n",
    "#不显示警告\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']  #显示中文\n",
    "plt.rcParams['axes.unicode_minus'] = False  #用来正常显示负号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "b9e8284d432a87c1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:15.779208400Z",
     "start_time": "2024-03-14T13:13:15.735244100Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "# 'skus' table 商品信息\n",
    "skus = pd.read_csv('./JD_data/JD_sku_data.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "b9c625a5f513cf9f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:16.542284700Z",
     "start_time": "2024-03-14T13:13:15.779208400Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "# 'orders' table 订单数据\n",
    "orders = pd.read_csv('./JD_data/JD_order_data.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "b5a4cffca62bdcdf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:25.114043600Z",
     "start_time": "2024-03-14T13:13:16.543284300Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "# 'clicks' table 点击数据\n",
    "clicks = pd.read_csv('./JD_data/JD_click_data.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "e7ccfc14e4228a8c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:25.330223500Z",
     "start_time": "2024-03-14T13:13:25.114043600Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "# 'users' table 用户信息\n",
    "users = pd.read_csv('./JD_data/JD_user_data.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "81fd683bc1ce19f0",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "\n",
    "## 查看重复值\n",
    "**思路**：利用merge连接观察是否少Example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "ebaf798f9eb8554b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:25.346378700Z",
     "start_time": "2024-03-14T13:13:25.332235800Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "def deduplicate(data, data_name):\n",
    "    before = data.shape[0]\n",
    "    data.drop_duplicates(inplace=True)\n",
    "    after = data.shape[0]\n",
    "    print(data_name + ': ' + str(before) + ' ' + str(after) + ' ' + str(before - after))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "initial_id",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:36.775035600Z",
     "start_time": "2024-03-14T13:13:25.453348Z"
    },
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "clicks: 20214515 19727248 487267\n",
      "orders: 549989 546061 3928\n",
      "users: 457298 457298 0\n",
      "skus: 31868 31868 0\n"
     ]
    }
   ],
   "source": [
    "deduplicate(clicks, 'clicks')\n",
    "deduplicate(orders, 'orders')\n",
    "deduplicate(users, 'users')\n",
    "deduplicate(skus, 'skus')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "7875c065749a3b3e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:36.797777900Z",
     "start_time": "2024-03-14T13:13:36.775035600Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19727248"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clicks.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "3a2984b8fe37692",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:56.133659500Z",
     "start_time": "2024-03-14T13:13:36.791236300Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_ID</th>\n",
       "      <th>request_time</th>\n",
       "      <th>channel</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sku_ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>000aa92b82</th>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000d4af39d</th>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000dc27e13</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>00104dbcd7</th>\n",
       "      <td>88</td>\n",
       "      <td>88</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>001b448016</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>fff4328ec0</th>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>fff84ed7ec</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>fffaaabb99</th>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>fffe1bd280</th>\n",
       "      <td>580</td>\n",
       "      <td>580</td>\n",
       "      <td>580</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>fffe6eb4df</th>\n",
       "      <td>18</td>\n",
       "      <td>18</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10789 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            user_ID  request_time  channel\n",
       "sku_ID                                    \n",
       "000aa92b82       12            12       12\n",
       "000d4af39d        7             7        7\n",
       "000dc27e13        1             1        1\n",
       "00104dbcd7       88            88       88\n",
       "001b448016        2             2        2\n",
       "...             ...           ...      ...\n",
       "fff4328ec0        8             8        8\n",
       "fff84ed7ec        5             5        5\n",
       "fffaaabb99        9             9        9\n",
       "fffe1bd280      580           580      580\n",
       "fffe6eb4df       18            18       18\n",
       "\n",
       "[10789 rows x 3 columns]"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clicks_repeat = pd.read_csv('./JD_data/JD_click_data.csv')\n",
    "df_d = clicks_repeat[clicks_repeat.duplicated()]\n",
    "df_d.groupby('sku_ID').count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "a2d251cc47f976cc",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:57.257090200Z",
     "start_time": "2024-03-14T13:13:56.134738300Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_ID</th>\n",
       "      <th>user_ID</th>\n",
       "      <th>order_date</th>\n",
       "      <th>order_time</th>\n",
       "      <th>quantity</th>\n",
       "      <th>type</th>\n",
       "      <th>promise</th>\n",
       "      <th>original_unit_price</th>\n",
       "      <th>final_unit_price</th>\n",
       "      <th>direct_discount_per_unit</th>\n",
       "      <th>quantity_discount_per_unit</th>\n",
       "      <th>bundle_discount_per_unit</th>\n",
       "      <th>coupon_discount_per_unit</th>\n",
       "      <th>gift_item</th>\n",
       "      <th>dc_ori</th>\n",
       "      <th>dc_des</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sku_ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>002cf934b4</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>03a2f9c7fd</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>04337ae7b0</th>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>04857dc39f</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>059ec11eff</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f2049aec3a</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f439039d74</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f843fb960c</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f9a92f7bd9</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>fc8c2eb2de</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>123 rows × 16 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            order_ID  user_ID  order_date  order_time  quantity  type  \\\n",
       "sku_ID                                                                  \n",
       "002cf934b4         3        3           3           3         3     3   \n",
       "03a2f9c7fd         1        1           1           1         1     1   \n",
       "04337ae7b0         6        6           6           6         6     6   \n",
       "04857dc39f         1        1           1           1         1     1   \n",
       "059ec11eff         2        2           2           2         2     2   \n",
       "...              ...      ...         ...         ...       ...   ...   \n",
       "f2049aec3a         1        1           1           1         1     1   \n",
       "f439039d74         5        5           5           5         5     5   \n",
       "f843fb960c         1        1           1           1         1     1   \n",
       "f9a92f7bd9         2        2           2           2         2     2   \n",
       "fc8c2eb2de         1        1           1           1         1     1   \n",
       "\n",
       "            promise  original_unit_price  final_unit_price  \\\n",
       "sku_ID                                                       \n",
       "002cf934b4        3                    3                 3   \n",
       "03a2f9c7fd        1                    1                 1   \n",
       "04337ae7b0        6                    6                 6   \n",
       "04857dc39f        1                    1                 1   \n",
       "059ec11eff        2                    2                 2   \n",
       "...             ...                  ...               ...   \n",
       "f2049aec3a        1                    1                 1   \n",
       "f439039d74        5                    5                 5   \n",
       "f843fb960c        1                    1                 1   \n",
       "f9a92f7bd9        2                    2                 2   \n",
       "fc8c2eb2de        1                    1                 1   \n",
       "\n",
       "            direct_discount_per_unit  quantity_discount_per_unit  \\\n",
       "sku_ID                                                             \n",
       "002cf934b4                         3                           3   \n",
       "03a2f9c7fd                         1                           1   \n",
       "04337ae7b0                         6                           6   \n",
       "04857dc39f                         1                           1   \n",
       "059ec11eff                         2                           2   \n",
       "...                              ...                         ...   \n",
       "f2049aec3a                         1                           1   \n",
       "f439039d74                         5                           5   \n",
       "f843fb960c                         1                           1   \n",
       "f9a92f7bd9                         2                           2   \n",
       "fc8c2eb2de                         1                           1   \n",
       "\n",
       "            bundle_discount_per_unit  coupon_discount_per_unit  gift_item  \\\n",
       "sku_ID                                                                      \n",
       "002cf934b4                         3                         3          3   \n",
       "03a2f9c7fd                         1                         1          1   \n",
       "04337ae7b0                         6                         6          6   \n",
       "04857dc39f                         1                         1          1   \n",
       "059ec11eff                         2                         2          2   \n",
       "...                              ...                       ...        ...   \n",
       "f2049aec3a                         1                         1          1   \n",
       "f439039d74                         5                         5          5   \n",
       "f843fb960c                         1                         1          1   \n",
       "f9a92f7bd9                         2                         2          2   \n",
       "fc8c2eb2de                         1                         1          1   \n",
       "\n",
       "            dc_ori  dc_des  \n",
       "sku_ID                      \n",
       "002cf934b4       3       3  \n",
       "03a2f9c7fd       1       1  \n",
       "04337ae7b0       6       6  \n",
       "04857dc39f       1       1  \n",
       "059ec11eff       2       2  \n",
       "...            ...     ...  \n",
       "f2049aec3a       1       1  \n",
       "f439039d74       5       5  \n",
       "f843fb960c       1       1  \n",
       "f9a92f7bd9       2       2  \n",
       "fc8c2eb2de       1       1  \n",
       "\n",
       "[123 rows x 16 columns]"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "orders_repeat = pd.read_csv('./JD_data/JD_order_data.csv')\n",
    "df_d = orders_repeat[orders_repeat.duplicated()]\n",
    "df_d.groupby('sku_ID').count()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "632b3bf674ac5e69",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "发现: 有大量重复点击，和较多的重复下单\n",
    "     并且以用户为单位，一些商品存在多次的重复点击和重复下单"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "2b74de239773a5d2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:57.346489700Z",
     "start_time": "2024-03-14T13:13:57.259090800Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_ID</th>\n",
       "      <th>user_level</th>\n",
       "      <th>first_order_month</th>\n",
       "      <th>plus</th>\n",
       "      <th>gender</th>\n",
       "      <th>age</th>\n",
       "      <th>marital_status</th>\n",
       "      <th>education</th>\n",
       "      <th>city_level</th>\n",
       "      <th>purchase_power</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [user_ID, user_level, first_order_month, plus, gender, age, marital_status, education, city_level, purchase_power]\n",
       "Index: []"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users.loc[users.first_order_month > '2018-03']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d729c84c9f144174",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "## 年龄预处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "3cdd66b37cd0a36",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:57.370785Z",
     "start_time": "2024-03-14T13:13:57.288652800Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "26-35    183239\n",
       "16-25    103306\n",
       "36-45     81076\n",
       "U         56457\n",
       "46-55     18679\n",
       ">=56      14517\n",
       "<=15         24\n",
       "Name: age, dtype: int64"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "counts = users['age'].value_counts(dropna=False)\n",
    "counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "abaa7bc858f99932",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:57.438078900Z",
     "start_time": "2024-03-14T13:13:57.319391300Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3     183239\n",
       "2     103306\n",
       "4      81076\n",
       "-1     70974\n",
       "5      18679\n",
       "1         24\n",
       "Name: age, dtype: int64"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def tranAge(x):\n",
    "    if x == '<=15':\n",
    "        x = '1'\n",
    "    elif x == '16-25':\n",
    "        x = '2'\n",
    "    elif x == '26-35':\n",
    "        x = '3'\n",
    "    elif x == '36-45':\n",
    "        x = '4'\n",
    "    elif x == '46-55':\n",
    "        x = '5'\n",
    "    else:\n",
    "        x = '-1'\n",
    "    return x\n",
    "\n",
    "\n",
    "users['age'] = users['age'].apply(tranAge)\n",
    "users['age'].value_counts(dropna=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dad002e9156e707b",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "## 构建 user_tabel\n",
    "user_tabel\n",
    "- user_ID\n",
    "- user_level, first_order_month, plus\n",
    "- gender, age, marital_status, education\n",
    "- city_level\n",
    "- purchase_power\n",
    "- **clicks_num 点击数**\n",
    "- **order_num 下单数**\n",
    "- **order_click_ratio 点击下单转化率**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "44d51195fb92a677",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:57.455871100Z",
     "start_time": "2024-03-14T13:13:57.381278200Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_ID              000089d6a6\n",
       "user_level                    1\n",
       "first_order_month       2017-08\n",
       "plus                          0\n",
       "gender                        F\n",
       "age                           3\n",
       "marital_status                S\n",
       "education                     3\n",
       "city_level                    4\n",
       "purchase_power                3\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "5b030c0710974b30",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:13:57.457871500Z",
     "start_time": "2024-03-14T13:13:57.397442600Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sku_ID             a234e08c57\n",
       "type                        1\n",
       "brand_ID           c3ab4bf4d9\n",
       "attribute1                3.0\n",
       "attribute2               60.0\n",
       "activate_date             NaN\n",
       "deactivate_date           NaN\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "skus.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "c7ec29fe3fb453e5",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:14:06.347192Z",
     "start_time": "2024-03-14T13:13:57.413333200Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "# 'orders' table 订单数据\n",
    "orders = pd.read_csv('./JD_data/JD_order_data.csv')\n",
    "# 'clicks' table 点击数据\n",
    "clicks = pd.read_csv('./JD_data/JD_click_data.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "c3002954ced3363d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:14:16.876609400Z",
     "start_time": "2024-03-14T13:14:06.348164500Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "# 合并数据表，这里使用左连接\n",
    "CL_OR = pd.merge(clicks, orders, on=['sku_ID', 'user_ID'], how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "5bed8a7f751809ba",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-15T12:47:10.207932Z",
     "start_time": "2024-03-15T12:47:10.173869200Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sku_ID</th>\n",
       "      <th>user_ID</th>\n",
       "      <th>request_time</th>\n",
       "      <th>channel</th>\n",
       "      <th>order_ID</th>\n",
       "      <th>order_date</th>\n",
       "      <th>order_time</th>\n",
       "      <th>quantity</th>\n",
       "      <th>type</th>\n",
       "      <th>promise</th>\n",
       "      <th>...</th>\n",
       "      <th>final_unit_price</th>\n",
       "      <th>direct_discount_per_unit</th>\n",
       "      <th>quantity_discount_per_unit</th>\n",
       "      <th>bundle_discount_per_unit</th>\n",
       "      <th>coupon_discount_per_unit</th>\n",
       "      <th>gift_item</th>\n",
       "      <th>dc_ori</th>\n",
       "      <th>dc_des</th>\n",
       "      <th>is_click</th>\n",
       "      <th>is_order</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>a234e08c57</td>\n",
       "      <td>4c3d6d10c2</td>\n",
       "      <td>2018-03-01 23:57:53</td>\n",
       "      <td>wechat</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6449e1fd87</td>\n",
       "      <td>-</td>\n",
       "      <td>2018-03-01 16:13:48</td>\n",
       "      <td>wechat</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>2791ec4485</td>\n",
       "      <td>2018-03-01 22:10:51</td>\n",
       "      <td>wechat</td>\n",
       "      <td>e4874e2a00</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>2018-03-01 14:08:33.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-</td>\n",
       "      <td>...</td>\n",
       "      <td>49.0</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>eb0718c1c9</td>\n",
       "      <td>2018-03-01 16:34:08</td>\n",
       "      <td>wechat</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>59f84cf342</td>\n",
       "      <td>2018-03-01 22:20:35</td>\n",
       "      <td>wechat</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       sku_ID     user_ID         request_time channel    order_ID  \\\n",
       "0  a234e08c57  4c3d6d10c2  2018-03-01 23:57:53  wechat         NaN   \n",
       "1  6449e1fd87           -  2018-03-01 16:13:48  wechat         NaN   \n",
       "2  09b70fcd83  2791ec4485  2018-03-01 22:10:51  wechat  e4874e2a00   \n",
       "3  09b70fcd83  eb0718c1c9  2018-03-01 16:34:08  wechat         NaN   \n",
       "4  09b70fcd83  59f84cf342  2018-03-01 22:20:35  wechat         NaN   \n",
       "\n",
       "   order_date             order_time  quantity  type promise  ...  \\\n",
       "0         NaN                    NaN       NaN   NaN     NaN  ...   \n",
       "1         NaN                    NaN       NaN   NaN     NaN  ...   \n",
       "2  2018-03-01  2018-03-01 14:08:33.0       1.0   2.0       -  ...   \n",
       "3         NaN                    NaN       NaN   NaN     NaN  ...   \n",
       "4         NaN                    NaN       NaN   NaN     NaN  ...   \n",
       "\n",
       "   final_unit_price  direct_discount_per_unit  quantity_discount_per_unit  \\\n",
       "0               NaN                       NaN                         NaN   \n",
       "1               NaN                       NaN                         NaN   \n",
       "2              49.0                      39.0                         0.0   \n",
       "3               NaN                       NaN                         NaN   \n",
       "4               NaN                       NaN                         NaN   \n",
       "\n",
       "   bundle_discount_per_unit  coupon_discount_per_unit  gift_item  dc_ori  \\\n",
       "0                       NaN                       NaN        NaN     NaN   \n",
       "1                       NaN                       NaN        NaN     NaN   \n",
       "2                       0.0                       0.0        0.0    24.0   \n",
       "3                       NaN                       NaN        NaN     NaN   \n",
       "4                       NaN                       NaN        NaN     NaN   \n",
       "\n",
       "   dc_des  is_click  is_order  \n",
       "0     NaN         1         0  \n",
       "1     NaN         1         0  \n",
       "2    40.0         1         1  \n",
       "3     NaN         1         0  \n",
       "4     NaN         1         0  \n",
       "\n",
       "[5 rows x 21 columns]"
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CL_OR.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "b5b20b7ef3abffe4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-15T12:47:36.234389500Z",
     "start_time": "2024-03-15T12:47:32.172714500Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "test = CL_OR[(CL_OR['sku_ID'] == '09b70fcd83') & (CL_OR['user_ID'] == '2791ec4485')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "efce550641f42955",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-15T12:47:39.843568700Z",
     "start_time": "2024-03-15T12:47:39.813280Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sku_ID</th>\n",
       "      <th>user_ID</th>\n",
       "      <th>request_time</th>\n",
       "      <th>channel</th>\n",
       "      <th>order_ID</th>\n",
       "      <th>order_date</th>\n",
       "      <th>order_time</th>\n",
       "      <th>quantity</th>\n",
       "      <th>type</th>\n",
       "      <th>promise</th>\n",
       "      <th>...</th>\n",
       "      <th>final_unit_price</th>\n",
       "      <th>direct_discount_per_unit</th>\n",
       "      <th>quantity_discount_per_unit</th>\n",
       "      <th>bundle_discount_per_unit</th>\n",
       "      <th>coupon_discount_per_unit</th>\n",
       "      <th>gift_item</th>\n",
       "      <th>dc_ori</th>\n",
       "      <th>dc_des</th>\n",
       "      <th>is_click</th>\n",
       "      <th>is_order</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>2791ec4485</td>\n",
       "      <td>2018-03-01 22:10:51</td>\n",
       "      <td>wechat</td>\n",
       "      <td>e4874e2a00</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>2018-03-01 14:08:33.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-</td>\n",
       "      <td>...</td>\n",
       "      <td>49.0</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>2791ec4485</td>\n",
       "      <td>2018-03-01 13:50:40</td>\n",
       "      <td>wechat</td>\n",
       "      <td>e4874e2a00</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>2018-03-01 14:08:33.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-</td>\n",
       "      <td>...</td>\n",
       "      <td>49.0</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>2791ec4485</td>\n",
       "      <td>2018-03-01 13:53:56</td>\n",
       "      <td>wechat</td>\n",
       "      <td>e4874e2a00</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>2018-03-01 14:08:33.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-</td>\n",
       "      <td>...</td>\n",
       "      <td>49.0</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>2791ec4485</td>\n",
       "      <td>2018-03-01 13:51:59</td>\n",
       "      <td>wechat</td>\n",
       "      <td>e4874e2a00</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>2018-03-01 14:08:33.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-</td>\n",
       "      <td>...</td>\n",
       "      <td>49.0</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>2791ec4485</td>\n",
       "      <td>2018-03-01 13:53:24</td>\n",
       "      <td>wechat</td>\n",
       "      <td>e4874e2a00</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>2018-03-01 14:08:33.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-</td>\n",
       "      <td>...</td>\n",
       "      <td>49.0</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>2791ec4485</td>\n",
       "      <td>2018-03-01 13:55:49</td>\n",
       "      <td>wechat</td>\n",
       "      <td>e4874e2a00</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>2018-03-01 14:08:33.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>-</td>\n",
       "      <td>...</td>\n",
       "      <td>49.0</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>6 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        sku_ID     user_ID         request_time channel    order_ID  \\\n",
       "2   09b70fcd83  2791ec4485  2018-03-01 22:10:51  wechat  e4874e2a00   \n",
       "11  09b70fcd83  2791ec4485  2018-03-01 13:50:40  wechat  e4874e2a00   \n",
       "12  09b70fcd83  2791ec4485  2018-03-01 13:53:56  wechat  e4874e2a00   \n",
       "13  09b70fcd83  2791ec4485  2018-03-01 13:51:59  wechat  e4874e2a00   \n",
       "14  09b70fcd83  2791ec4485  2018-03-01 13:53:24  wechat  e4874e2a00   \n",
       "15  09b70fcd83  2791ec4485  2018-03-01 13:55:49  wechat  e4874e2a00   \n",
       "\n",
       "    order_date             order_time  quantity  type promise  ...  \\\n",
       "2   2018-03-01  2018-03-01 14:08:33.0       1.0   2.0       -  ...   \n",
       "11  2018-03-01  2018-03-01 14:08:33.0       1.0   2.0       -  ...   \n",
       "12  2018-03-01  2018-03-01 14:08:33.0       1.0   2.0       -  ...   \n",
       "13  2018-03-01  2018-03-01 14:08:33.0       1.0   2.0       -  ...   \n",
       "14  2018-03-01  2018-03-01 14:08:33.0       1.0   2.0       -  ...   \n",
       "15  2018-03-01  2018-03-01 14:08:33.0       1.0   2.0       -  ...   \n",
       "\n",
       "    final_unit_price  direct_discount_per_unit  quantity_discount_per_unit  \\\n",
       "2               49.0                      39.0                         0.0   \n",
       "11              49.0                      39.0                         0.0   \n",
       "12              49.0                      39.0                         0.0   \n",
       "13              49.0                      39.0                         0.0   \n",
       "14              49.0                      39.0                         0.0   \n",
       "15              49.0                      39.0                         0.0   \n",
       "\n",
       "    bundle_discount_per_unit  coupon_discount_per_unit  gift_item  dc_ori  \\\n",
       "2                        0.0                       0.0        0.0    24.0   \n",
       "11                       0.0                       0.0        0.0    24.0   \n",
       "12                       0.0                       0.0        0.0    24.0   \n",
       "13                       0.0                       0.0        0.0    24.0   \n",
       "14                       0.0                       0.0        0.0    24.0   \n",
       "15                       0.0                       0.0        0.0    24.0   \n",
       "\n",
       "    dc_des  is_click  is_order  \n",
       "2     40.0         1         1  \n",
       "11    40.0         1         1  \n",
       "12    40.0         1         1  \n",
       "13    40.0         1         1  \n",
       "14    40.0         1         1  \n",
       "15    40.0         1         1  \n",
       "\n",
       "[6 rows x 21 columns]"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "f489fb85f5cf7346",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:14:16.925833200Z",
     "start_time": "2024-03-14T13:14:16.893618Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20321457"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CL_OR.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "14712d52cdf0f1a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:12.235304100Z",
     "start_time": "2024-03-14T13:14:16.911017300Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "CL_OR.to_csv('CL_OR.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "875cb4345a8d21cb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:12.250960Z",
     "start_time": "2024-03-14T13:15:12.235304100Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "457298"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "5025f814d6f250cb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:13.052705300Z",
     "start_time": "2024-03-14T13:15:12.251964200Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "# CL_OR 多增两个属性--是否下单和点击\n",
    "CL_OR['is_click'] = CL_OR['request_time'].notnull().astype(int)\n",
    "CL_OR['is_order'] = CL_OR['order_time'].notnull().astype(int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "9902063b84c4281f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:19.411006300Z",
     "start_time": "2024-03-14T13:15:13.054711Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "user_metrics = CL_OR.groupby('user_ID').agg({\n",
    "    'is_click': 'sum',\n",
    "    'is_order': 'sum'\n",
    "}).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "555558dfc52e5e7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:19.445195100Z",
     "start_time": "2024-03-14T13:15:19.413021100Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "user_metrics['order_click_ratio'] = user_metrics['is_order'] / user_metrics['is_click'].replace(0, pd.NA)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "2c0af98db5f52093",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:19.462969900Z",
     "start_time": "2024-03-14T13:15:19.444195Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2557837"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_metrics.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "84558afed3f4f05e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:19.488523Z",
     "start_time": "2024-03-14T13:15:19.458727400Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_ID                    -\n",
       "is_click             2308420\n",
       "is_order                   0\n",
       "order_click_ratio        0.0\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_metrics.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "688b5fa57efa64eb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:20.831333200Z",
     "start_time": "2024-03-14T13:15:19.474989200Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "users_expand = pd.merge(users, user_metrics, on=['user_ID'], how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "32a0bd1a0048f84a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:20.848016200Z",
     "start_time": "2024-03-14T13:15:20.834337200Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "457298"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users_expand.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "3794595151168e79",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:20.881300200Z",
     "start_time": "2024-03-14T13:15:20.848016200Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_ID</th>\n",
       "      <th>user_level</th>\n",
       "      <th>first_order_month</th>\n",
       "      <th>plus</th>\n",
       "      <th>gender</th>\n",
       "      <th>age</th>\n",
       "      <th>marital_status</th>\n",
       "      <th>education</th>\n",
       "      <th>city_level</th>\n",
       "      <th>purchase_power</th>\n",
       "      <th>is_click</th>\n",
       "      <th>is_order</th>\n",
       "      <th>order_click_ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000089d6a6</td>\n",
       "      <td>1</td>\n",
       "      <td>2017-08</td>\n",
       "      <td>0</td>\n",
       "      <td>F</td>\n",
       "      <td>3</td>\n",
       "      <td>S</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>10.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.800000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0000babd1f</td>\n",
       "      <td>1</td>\n",
       "      <td>2018-03</td>\n",
       "      <td>0</td>\n",
       "      <td>U</td>\n",
       "      <td>-1</td>\n",
       "      <td>U</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0000bc018b</td>\n",
       "      <td>3</td>\n",
       "      <td>2016-06</td>\n",
       "      <td>0</td>\n",
       "      <td>F</td>\n",
       "      <td>-1</td>\n",
       "      <td>M</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>16.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0000d0e5ab</td>\n",
       "      <td>3</td>\n",
       "      <td>2014-06</td>\n",
       "      <td>0</td>\n",
       "      <td>M</td>\n",
       "      <td>3</td>\n",
       "      <td>M</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0000dce472</td>\n",
       "      <td>3</td>\n",
       "      <td>2012-08</td>\n",
       "      <td>1</td>\n",
       "      <td>U</td>\n",
       "      <td>-1</td>\n",
       "      <td>U</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>0.611111</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      user_ID  user_level first_order_month  plus gender age marital_status  \\\n",
       "0  000089d6a6           1           2017-08     0      F   3              S   \n",
       "1  0000babd1f           1           2018-03     0      U  -1              U   \n",
       "2  0000bc018b           3           2016-06     0      F  -1              M   \n",
       "3  0000d0e5ab           3           2014-06     0      M   3              M   \n",
       "4  0000dce472           3           2012-08     1      U  -1              U   \n",
       "\n",
       "   education  city_level  purchase_power  is_click  is_order  \\\n",
       "0          3           4               3      10.0       8.0   \n",
       "1         -1          -1              -1       2.0       2.0   \n",
       "2          3           2               3      16.0       8.0   \n",
       "3          3           2               2       2.0       2.0   \n",
       "4         -1          -1              -1      18.0      11.0   \n",
       "\n",
       "   order_click_ratio  \n",
       "0           0.800000  \n",
       "1           1.000000  \n",
       "2           0.500000  \n",
       "3           1.000000  \n",
       "4           0.611111  "
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users_expand.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e91e7bb7bd440124",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "## 构建 sku_tabel\n",
    "- sku_ID\n",
    "- type\n",
    "- brand_ID\n",
    "- attribute1\n",
    "- attribute2\n",
    "- activate_date\n",
    "- deactivate_date\n",
    "- **clicks_num 点击数**\n",
    "- **order_num 下单数**\n",
    "- **order_click_ratio 点击下单转化率**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "af21a47912254b78",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:20.894386700Z",
     "start_time": "2024-03-14T13:15:20.865440100Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "31868"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "skus.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "f069ccdc0d91b9d7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:20.950416100Z",
     "start_time": "2024-03-14T13:15:20.881300200Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sku_ID             a234e08c57\n",
       "type                        1\n",
       "brand_ID           c3ab4bf4d9\n",
       "attribute1                3.0\n",
       "attribute2               60.0\n",
       "activate_date             NaN\n",
       "deactivate_date           NaN\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "skus.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "12fa9ea815fd5cd1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:21.927946600Z",
     "start_time": "2024-03-14T13:15:20.897387900Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "sku_metrics = CL_OR.groupby('sku_ID').agg({\n",
    "    'is_click': 'sum',\n",
    "    'is_order': 'sum'\n",
    "}).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "970f49c6021823c1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:21.945056800Z",
     "start_time": "2024-03-14T13:15:21.928946600Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "sku_metrics['order_click_ratio'] = sku_metrics['is_order'] / sku_metrics['is_click'].replace(0, pd.NA)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "c70395010ad18cad",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:21.980319400Z",
     "start_time": "2024-03-14T13:15:21.946057700Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "31868"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sku_expand = pd.merge(skus, sku_metrics, on=['sku_ID'], how='left')\n",
    "sku_expand.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "e9479211a8c5d5e8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:22.005957100Z",
     "start_time": "2024-03-14T13:15:21.977318500Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sku_ID</th>\n",
       "      <th>type</th>\n",
       "      <th>brand_ID</th>\n",
       "      <th>attribute1</th>\n",
       "      <th>attribute2</th>\n",
       "      <th>activate_date</th>\n",
       "      <th>deactivate_date</th>\n",
       "      <th>is_click</th>\n",
       "      <th>is_order</th>\n",
       "      <th>order_click_ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>a234e08c57</td>\n",
       "      <td>1</td>\n",
       "      <td>c3ab4bf4d9</td>\n",
       "      <td>3.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>644</td>\n",
       "      <td>74</td>\n",
       "      <td>0.114907</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6449e1fd87</td>\n",
       "      <td>1</td>\n",
       "      <td>1d8b4b4c63</td>\n",
       "      <td>2.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>871</td>\n",
       "      <td>123</td>\n",
       "      <td>0.141217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>09b70fcd83</td>\n",
       "      <td>2</td>\n",
       "      <td>eb7d2a675a</td>\n",
       "      <td>3.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4860</td>\n",
       "      <td>699</td>\n",
       "      <td>0.143827</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>acad9fed04</td>\n",
       "      <td>2</td>\n",
       "      <td>9b0d3a5fc6</td>\n",
       "      <td>3.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5298</td>\n",
       "      <td>222</td>\n",
       "      <td>0.041903</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2fa77e3b4d</td>\n",
       "      <td>2</td>\n",
       "      <td>b681299668</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2360</td>\n",
       "      <td>139</td>\n",
       "      <td>0.058898</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       sku_ID  type    brand_ID attribute1 attribute2 activate_date  \\\n",
       "0  a234e08c57     1  c3ab4bf4d9        3.0       60.0           NaN   \n",
       "1  6449e1fd87     1  1d8b4b4c63        2.0       50.0           NaN   \n",
       "2  09b70fcd83     2  eb7d2a675a        3.0       70.0           NaN   \n",
       "3  acad9fed04     2  9b0d3a5fc6        3.0       70.0           NaN   \n",
       "4  2fa77e3b4d     2  b681299668          -          -           NaN   \n",
       "\n",
       "  deactivate_date  is_click  is_order  order_click_ratio  \n",
       "0             NaN       644        74           0.114907  \n",
       "1             NaN       871       123           0.141217  \n",
       "2             NaN      4860       699           0.143827  \n",
       "3             NaN      5298       222           0.041903  \n",
       "4             NaN      2360       139           0.058898  "
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sku_expand.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "f0da27f1ebe0bf77",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:22.898138700Z",
     "start_time": "2024-03-14T13:15:21.992445900Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "sku_expand.to_csv('sku_expand.csv', index=False)\n",
    "users_expand.to_csv('user_expand.csv', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8bac33881481ef01",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "## 数据清洗"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aec3531bdab236d0",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "### 删除无交互记录的用户"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "43acb1c6da4aca67",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:23.193268600Z",
     "start_time": "2024-03-14T13:15:22.898138700Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "users = pd.read_csv('./user_expand.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "id": "726147a8145f1d43",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:23.300137500Z",
     "start_time": "2024-03-14T13:15:23.194270300Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_level</th>\n",
       "      <th>plus</th>\n",
       "      <th>age</th>\n",
       "      <th>education</th>\n",
       "      <th>city_level</th>\n",
       "      <th>purchase_power</th>\n",
       "      <th>is_click</th>\n",
       "      <th>is_order</th>\n",
       "      <th>order_click_ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>457298.000000</td>\n",
       "      <td>457298.000000</td>\n",
       "      <td>457298.000000</td>\n",
       "      <td>457298.000000</td>\n",
       "      <td>457298.000000</td>\n",
       "      <td>457298.000000</td>\n",
       "      <td>396110.000000</td>\n",
       "      <td>396110.000000</td>\n",
       "      <td>396110.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>2.305547</td>\n",
       "      <td>0.177031</td>\n",
       "      <td>2.412164</td>\n",
       "      <td>1.938830</td>\n",
       "      <td>1.688945</td>\n",
       "      <td>1.585170</td>\n",
       "      <td>15.890775</td>\n",
       "      <td>6.653460</td>\n",
       "      <td>0.573673</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>1.157647</td>\n",
       "      <td>0.381695</td>\n",
       "      <td>1.644536</td>\n",
       "      <td>1.752484</td>\n",
       "      <td>1.608057</td>\n",
       "      <td>1.461573</td>\n",
       "      <td>24.467093</td>\n",
       "      <td>12.256294</td>\n",
       "      <td>0.329963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.300000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>0.555556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>3.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>19.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>0.965517</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>10.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>3776.000000</td>\n",
       "      <td>3750.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          user_level           plus            age      education  \\\n",
       "count  457298.000000  457298.000000  457298.000000  457298.000000   \n",
       "mean        2.305547       0.177031       2.412164       1.938830   \n",
       "std         1.157647       0.381695       1.644536       1.752484   \n",
       "min        -1.000000       0.000000      -1.000000      -1.000000   \n",
       "25%         1.000000       0.000000       2.000000       1.000000   \n",
       "50%         2.000000       0.000000       3.000000       3.000000   \n",
       "75%         3.000000       0.000000       3.000000       3.000000   \n",
       "max        10.000000       1.000000       5.000000       4.000000   \n",
       "\n",
       "          city_level  purchase_power       is_click       is_order  \\\n",
       "count  457298.000000   457298.000000  396110.000000  396110.000000   \n",
       "mean        1.688945        1.585170      15.890775       6.653460   \n",
       "std         1.608057        1.461573      24.467093      12.256294   \n",
       "min        -1.000000       -1.000000       1.000000       0.000000   \n",
       "25%         1.000000        2.000000       4.000000       2.000000   \n",
       "50%         2.000000        2.000000       9.000000       4.000000   \n",
       "75%         3.000000        2.000000      19.000000       8.000000   \n",
       "max         5.000000        5.000000    3776.000000    3750.000000   \n",
       "\n",
       "       order_click_ratio  \n",
       "count      396110.000000  \n",
       "mean            0.573673  \n",
       "std             0.329963  \n",
       "min             0.000000  \n",
       "25%             0.300000  \n",
       "50%             0.555556  \n",
       "75%             0.965517  \n",
       "max             1.000000  "
      ]
     },
     "execution_count": 128,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "id": "87e2ffc1d94a8668",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:23.393815100Z",
     "start_time": "2024-03-14T13:15:23.302275200Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "396110"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users_naction = users[(users['is_click'].isnull()) & (users['is_order'].isnull())]\n",
    "users.drop(users_naction.index, axis=0, inplace=True)\n",
    "users.shape[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebdb8d24f6a1a924",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": [
    "### 删除爬虫用户或者惰性用户"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "id": "da3efe288d77a940",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:23.395819300Z",
     "start_time": "2024-03-14T13:15:23.381095900Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "22275"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inertia_users = users[users['order_click_ratio'] < 0.0005]\n",
    "inertia_users.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "id": "5785c78a1760403e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:23.428700100Z",
     "start_time": "2024-03-14T13:15:23.394819600Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_ID</th>\n",
       "      <th>user_level</th>\n",
       "      <th>first_order_month</th>\n",
       "      <th>plus</th>\n",
       "      <th>gender</th>\n",
       "      <th>age</th>\n",
       "      <th>marital_status</th>\n",
       "      <th>education</th>\n",
       "      <th>city_level</th>\n",
       "      <th>purchase_power</th>\n",
       "      <th>is_click</th>\n",
       "      <th>is_order</th>\n",
       "      <th>order_click_ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>00047a0b67</td>\n",
       "      <td>1</td>\n",
       "      <td>2017-09</td>\n",
       "      <td>0</td>\n",
       "      <td>F</td>\n",
       "      <td>2</td>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>0007ae94c5</td>\n",
       "      <td>2</td>\n",
       "      <td>2017-03</td>\n",
       "      <td>0</td>\n",
       "      <td>F</td>\n",
       "      <td>2</td>\n",
       "      <td>S</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>23.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>000c66c723</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-03</td>\n",
       "      <td>0</td>\n",
       "      <td>F</td>\n",
       "      <td>2</td>\n",
       "      <td>S</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>000f0deec9</td>\n",
       "      <td>3</td>\n",
       "      <td>2013-04</td>\n",
       "      <td>0</td>\n",
       "      <td>F</td>\n",
       "      <td>3</td>\n",
       "      <td>S</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>9.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>000ff854e7</td>\n",
       "      <td>1</td>\n",
       "      <td>2018-01</td>\n",
       "      <td>0</td>\n",
       "      <td>U</td>\n",
       "      <td>-1</td>\n",
       "      <td>U</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       user_ID  user_level first_order_month  plus gender  age marital_status  \\\n",
       "22  00047a0b67           1           2017-09     0      F    2              S   \n",
       "36  0007ae94c5           2           2017-03     0      F    2              S   \n",
       "61  000c66c723           1           2014-03     0      F    2              S   \n",
       "79  000f0deec9           3           2013-04     0      F    3              S   \n",
       "83  000ff854e7           1           2018-01     0      U   -1              U   \n",
       "\n",
       "    education  city_level  purchase_power  is_click  is_order  \\\n",
       "22          2           3               2       5.0       0.0   \n",
       "36          3           1               2      23.0       0.0   \n",
       "61          3           3               3       3.0       0.0   \n",
       "79          3           2               2       9.0       0.0   \n",
       "83         -1          -1              -1       4.0       0.0   \n",
       "\n",
       "    order_click_ratio  \n",
       "22                0.0  \n",
       "36                0.0  \n",
       "61                0.0  \n",
       "79                0.0  \n",
       "83                0.0  "
      ]
     },
     "execution_count": 131,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inertia_users.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "id": "a344dce86306d875",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:23.481022100Z",
     "start_time": "2024-03-14T13:15:23.410030400Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "users.drop(index=inertia_users.index, axis=0, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "id": "bed3138efca80813",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:23.482026300Z",
     "start_time": "2024-03-14T13:15:23.456922700Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_ID</th>\n",
       "      <th>user_level</th>\n",
       "      <th>first_order_month</th>\n",
       "      <th>plus</th>\n",
       "      <th>gender</th>\n",
       "      <th>age</th>\n",
       "      <th>marital_status</th>\n",
       "      <th>education</th>\n",
       "      <th>city_level</th>\n",
       "      <th>purchase_power</th>\n",
       "      <th>is_click</th>\n",
       "      <th>is_order</th>\n",
       "      <th>order_click_ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000089d6a6</td>\n",
       "      <td>1</td>\n",
       "      <td>2017-08</td>\n",
       "      <td>0</td>\n",
       "      <td>F</td>\n",
       "      <td>3</td>\n",
       "      <td>S</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>10.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.800000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0000babd1f</td>\n",
       "      <td>1</td>\n",
       "      <td>2018-03</td>\n",
       "      <td>0</td>\n",
       "      <td>U</td>\n",
       "      <td>-1</td>\n",
       "      <td>U</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0000bc018b</td>\n",
       "      <td>3</td>\n",
       "      <td>2016-06</td>\n",
       "      <td>0</td>\n",
       "      <td>F</td>\n",
       "      <td>-1</td>\n",
       "      <td>M</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>16.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0000d0e5ab</td>\n",
       "      <td>3</td>\n",
       "      <td>2014-06</td>\n",
       "      <td>0</td>\n",
       "      <td>M</td>\n",
       "      <td>3</td>\n",
       "      <td>M</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0000dce472</td>\n",
       "      <td>3</td>\n",
       "      <td>2012-08</td>\n",
       "      <td>1</td>\n",
       "      <td>U</td>\n",
       "      <td>-1</td>\n",
       "      <td>U</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>18.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>0.611111</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      user_ID  user_level first_order_month  plus gender  age marital_status  \\\n",
       "0  000089d6a6           1           2017-08     0      F    3              S   \n",
       "1  0000babd1f           1           2018-03     0      U   -1              U   \n",
       "2  0000bc018b           3           2016-06     0      F   -1              M   \n",
       "3  0000d0e5ab           3           2014-06     0      M    3              M   \n",
       "4  0000dce472           3           2012-08     1      U   -1              U   \n",
       "\n",
       "   education  city_level  purchase_power  is_click  is_order  \\\n",
       "0          3           4               3      10.0       8.0   \n",
       "1         -1          -1              -1       2.0       2.0   \n",
       "2          3           2               3      16.0       8.0   \n",
       "3          3           2               2       2.0       2.0   \n",
       "4         -1          -1              -1      18.0      11.0   \n",
       "\n",
       "   order_click_ratio  \n",
       "0           0.800000  \n",
       "1           1.000000  \n",
       "2           0.500000  \n",
       "3           1.000000  \n",
       "4           0.611111  "
      ]
     },
     "execution_count": 133,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "2b394fb38c68c9fd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:24.276160400Z",
     "start_time": "2024-03-14T13:15:23.473000900Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "users.to_csv('user_expand.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "id": "23fd7c12bb5998b9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-14T13:15:24.292279600Z",
     "start_time": "2024-03-14T13:15:24.276160400Z"
    },
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "373835"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users.shape[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67f92f48eb1cc7de",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
